package com.meta.nd.filter.vo;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.meta.common.ConstDef;
import com.meta.nd.util.NodeUtil;


import java.io.IOException;
import java.util.Date;

public class FilterFdSerializer extends JsonSerializer<FilterFd> {
    @Override
    public void serialize(FilterFd filterFd, JsonGenerator jgen, SerializerProvider provider)
            throws IOException, JsonProcessingException {
        if ( filterFd.getDataType().equals(ConstDef.DATA_TYPE_DATE))
            jgen.writeObjectField("value", NodeUtil.formatDate((Date)filterFd.getValue()));
        else if ( filterFd.getDataType().equals(ConstDef.DATA_TYPE_DATETIME))
            jgen.writeObjectField("value", NodeUtil.formatDatetime((Date)filterFd.getValue()));

        jgen.writeObjectField("ndName", filterFd.getNdName());
        jgen.writeObjectField("dataType", filterFd.getDataType());
        jgen.writeObjectField("fdName", filterFd.getFdName());
        jgen.writeObjectField("fdAlias", filterFd.getFdAlias());
        jgen.writeObjectField("fixedValue", filterFd.getFixedValue());
        jgen.writeObjectField("serNo", filterFd.getSerNo());
        jgen.writeObjectField("logicalOperator", filterFd.getLogicalOperator());

    }
}
